package com.example.mine.viewmodel

import android.util.Log
import com.bw.common.base.BaseViewModel
import com.example.common.entity.Res
import com.example.common.entity.SendLoginCodeEntity
import com.example.mine.model.UserRepository

import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject
import kotlin.math.log

@HiltViewModel
class UserViewModel @Inject constructor(
    private val repository: UserRepository
):BaseViewModel(){
    private val _userState = MutableStateFlow<Res<Boolean>>(Res.loading())
    val userState: StateFlow<Res<Boolean>> =_userState
    fun loadHome(operatorType:String,phone:String){
        launchFlow(
            flow = repository.getSendLoginCode(operatorType, phone),
            onStart = {
                Log.d("TAG", "loadHome:你好 ")
                _userState.value= Res.loading()
                      },
            onSuccess = {list->
                _userState.value=Res.success(list)
                Log.d("TAG", "loadHome:${list} ")
            },
            onError = {msg->
                _userState.value= Res.error(msg)
                Log.d("TAG", "loadHome:${msg} ")
            }
        )
    }
}